<!DOCTYPE html>
<!--

Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

-->
<html lang="en">
  <head>
    <title>Statistics</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    <link rel="stylesheet" href="style/layout.css?0.11.0" type="text/css">

		<style type="text/css">
			p.help {
				float: left;
			}

			p#summary.help a {
				padding-right: 10px;
			}

			table#config.listing {
				clear: both;
			}

			table#config.listing th.colSection,
			table#config.listing th.colOption {
				width: 25%;
			}
		</style>

    <script src="script/json2.js"></script>
    <script src="script/sha1.js"></script>
    <script src="script/jquery.js?1.4.2"></script>
    <script src="script/jquery.couch.js?0.11.0"></script>
    <script src="script/jquery.dialog.js?0.11.0"></script>
    <script src="script/futon.js?0.11.0"></script>
    <script>
      $(function() {
				// Retrieve/Load _stats
				$.ajax({
					"url": "/_stats",
					"error": function(jqXHR, textStatus, errorThrown) {
						// Main message
						var msg="Message: An error occured during retrieving _stats.\n\n";

						// Add Text-Status
						msg+="Text status:\n"+textStatus+"\n\n";

						// Add errorThrown
						msg+="Error thrown:\n"+errorThrown+"\n\n";

						// Display error message
						alert(msg);
					},
					"success": function(data, textStatus, jqXHR) {
						// Save sections
						var sections=[];
						for (var sectionName in data) {
							sections.push(sectionName);
							// Add sections to anchor-summary
							$("#summary").append("<a href=\"#"+sectionName+"\">"+sectionName+"</a>");
						}

						// Run through sections
						$(sections).each(function(sectionIndex, sectionName) {
							// Save options
							var options=[];
							for (var optionName in data[sectionName]) options.push(optionName);

							// Run through options
							$(options).each(function(optionIndex, optionName) {
								// Save values
								var values=[];
								for (var valueName in data[sectionName][optionName]) values.push(valueName);

								// Run through values
								$(values).each(function(valueIndex, valueName) {
									$("table#config.listing tbody.content").append(
										"<tr>"+
										(optionIndex==0 && valueIndex==0?"<th id=\"section_"+sectionName+"\" rowspan=\"0\"><a name=\""+sectionName+"\">"+sectionName+"</th>":"")+
										(valueIndex==0?"<td id=\"option_"+sectionName+"_"+optionName+"\" class=\"name\">"+optionName+"</td>":"")+
										"<td class=\"name\">"+valueName+"</td>"+
										"<td class=\"code\">"+data[sectionName][optionName][valueName]+"</td>"+
										"</tr>"
									);
								});

								// Rowspan section
								$("#section_"+sectionName).attr("rowspan", ($("#section_"+sectionName).attr("rowspan")*1)+values.length); 
								// Rowspan option
								$("#option_"+sectionName+"_"+optionName).attr("rowspan", values.length);
							});
						});
					},
					"dataType":	"json" 
				});
			});
    </script>
  </head>
  <body><div id="wrap">
    <h1>
      <a href="index.html">Overview</a>
      <strong>Statistics</strong>
    </h1>
    <div id="content">
			<div>
				<p class="help">
					<b>Note:</b><br>
					For plain-text of <i>_stats</i> click <a href="/_stats" target="_blank">here</a>.
				</p>
				<p id="summary" class="help">
					<b>Summary:</b><br>
				</p>
			</div>
      <table id="config" class="listing" cellspacing="0">
        <caption>Statistics</caption>
        <thead><tr>
          <th class="colSection">Section</th>
          <th class="colOption">Options</th>
					<th>Name</th>
          <th>Value</th>
        </tr></thead>
        <tbody class="content"></tbody>
      </table>

    </div>
  </div></body>
</html>
